package it.lupo.model.service;

import it.lupo.model.BarCode;
import it.lupo.repository.HibernateSessionFactory;
import it.lupo.repository.dao.BarCodeDAO;

import java.util.List;

import org.hibernate.Session;
import org.hibernate.Transaction;

public class SearchService {

	private static SearchService instance;
	private SearchService(){}
	public static SearchService getInstance()
	{
		if(instance==null)
			instance = new SearchService();
		return instance;
	}
	
	
	public List<BarCode> search(String barcode,String cf,String address,String email,String name,String surname)
	{
		
		Session session = HibernateSessionFactory.getSession();
		Transaction trx = session.beginTransaction();
		try{	
			BarCodeDAO udao = new BarCodeDAO();
			
			List<BarCode> list = udao.search(barcode,cf,address,email,name, surname);
			
			trx.commit();
			session.close();
			return list;
		}catch(Exception e)
		{
			e.printStackTrace();
			trx.rollback();	
			session.close();
			return null;
		}
	}
}
